<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<!--
	if this is a nested component, the global stylesheet parameters $renderId and $border
	are not used. Instead, the NodeHandler may define @border and @renderId attributes
	-->
	
	<xsl:param name="imgpath1" select="'stpivot/style/wcf/tree'"/>
	<xsl:param name="tree-border" select="'0'"/>
	
	<xsl:template name="xtree-renderId">
		<xsl:choose>
			<xsl:when test="@renderId">
				<xsl:value-of select="@renderId"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$renderId"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template name="xtree-border">
		<xsl:choose>
			<xsl:when test="@border">
				<xsl:value-of select="@border"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$tree-border"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<!--
	for handwritten xtree element where the tree is part of a form
	-->
	
	<xsl:template match="xtree">
		<xsl:apply-templates/>
	</xsl:template>
	
	<xsl:template match="xtree-component">
		<table cellspacing="0" width="100%">
			<xsl:attribute name="id">
				<xsl:call-template name="xtree-renderId"/>
			</xsl:attribute>
			<xsl:attribute name="border">
				<xsl:call-template name="xtree-border"/>
			</xsl:attribute>
			<xsl:attribute name="cellpadding">
				<xsl:call-template name="xtree-border"/>
			</xsl:attribute>
			<xsl:if test="@width">
				<xsl:attribute name="width">
					<xsl:value-of select="@width"/>
				</xsl:attribute>
			</xsl:if>
			<xsl:call-template name="xtree-title"/>
			<xsl:apply-templates select="tree-extras-top"/>
			<xsl:apply-templates select="tree-node"/>
			<xsl:apply-templates select="tree-extras-bottom"/>
			<xsl:apply-templates select="buttons"/>
		</table>
	</xsl:template>
	
	<xsl:template name="xtree-title">
		<xsl:if test="@title or @closeId">
			<tr>
				<th class="navi-axis">
					<table border="0" cellspacing="0" cellpadding="0" width="100%">
						<tr>
							<xsl:if test="@title">
								<th align="left" class="xform-title">
									<xsl:value-of select="@title"/>
								</th>
							</xsl:if>
							<!--xsl:if test="@closeId">
								<td align="right" class="xform-close-button">
									<input type="image" src="{$context}/{$imgpath1}/../form/cancel.png" name="{@closeId}" width="16" height="16" class="imgButton"/>
								</td>
							</xsl:if-->
						</tr>
					</table>
				</th>
			</tr>
		</xsl:if>
		<xsl:if test="@error">
			<tr>
				<td class="xform-error">
					<xsl:value-of select="@error"/>
				</td>
			</tr>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="tree-node">
		<tr>
			<td nowrap="nowrap" class="tree-node-{@style}">
				
				<div style="margin-left: {@level}em">
					<!-- checkbox / radiobox is handled by controls.xsl -->
					<xsl:apply-templates select="checkBox|radioButton"/>
        
					<xsl:if test="@buttonId">
						<xsl:choose>
							<xsl:when test="@selected">
								<input border="0" type="image" name="{@buttonId}" src="{$context}/{$imgpath1}/select1.png" width="13" height="13" class="imgButton"/>
								<xsl:text> </xsl:text>
							</xsl:when>
							<xsl:otherwise>
								<input border="0" type="image" name="{@buttonId}" src="{$context}/{$imgpath1}/select0.png" width="13" height="13" class="imgButton"/>
								<xsl:text> </xsl:text>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:if>
					
					<!-- expand/collapse button -->
					<xsl:choose>
						<xsl:when test="@state='bounded'">
							<input border="0" type="image" name="{@id}.unbound" src="{$context}/{$imgpath1}/unbound.png" width="9" height="9" class="imgButton"/>
						</xsl:when>
						<xsl:when test="@state='expanded'">
							<input border="0" type="image" name="{@id}.collapse" src="{$context}/{$imgpath1}/collapse.png" width="9" height="9" class="imgButton"/>
						</xsl:when>
						<xsl:when test="@state='collapsed'">
							<input border="0" type="image" name="{@id}.expand" src="{$context}/{$imgpath1}/expand.png" width="9" height="9" class="imgButton"/>
						</xsl:when>
						<xsl:otherwise>
							<img src="{$context}/{$imgpath1}/leaf.png" width="9" height="9"/>
						</xsl:otherwise>
					</xsl:choose>
					
					<xsl:apply-templates select="move-button"/>
					
					<xsl:text> </xsl:text>
					<xsl:choose>
						<xsl:when test="@hrefId">
							<a href="#" onclick="drillNavigator('{$token}&amp;{@id}=x&amp;pivotPart=navi',false,false)">
								<xsl:value-of select="@label"/>
							</a>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="@label"/>
						</xsl:otherwise>
					</xsl:choose>
					
					<xsl:apply-templates select="delete-button"/>
				</div>
			</td>
		</tr>
		<xsl:apply-templates select="tree-node"/>
	</xsl:template>
	
	<xsl:template match="delete-button">
		<xsl:text> </xsl:text>
		<input type="image" border="0" name="{@id}" src="{$context}/{$imgpath1}/delete.png" width="9" height="9"/>
	</xsl:template>
	
	<xsl:template match="buttons">
		<tr>
			<td align="right">
				<div align="right">
					<xsl:apply-templates/>
				</div>
			</td>
		</tr>
	</xsl:template>
	
</xsl:stylesheet>